// **************************************************************
// Com ++ Framework by the C++ World
// Please report defects: mailto:compp@cplusplusworld.com
// Please visit: http://www.cplusplusworld.com/socketlibrary.html
// **************************************************************

#include <iostream>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#include "ComPlusPlus/ComPlusPlus"

int main( int argc, char * argv [] ) {

  if ( argc != 2 ) {
    std::cout << "usage: ExampleSem post|wait|local\n";
    exit (1);
  }

  if ( strcmp ( argv [ 1 ], "post") == 0  ) {
    compp::Sem *s1 = new compp::Sem ( true, 1 )  ;
    for ( int i = 0; i++ < 10; ) {
      s1->Post();
    } 

  } else {
    if ( strcmp ( argv [ 1 ], "wait") == 0  ) {
      compp::Sem *s1 = new compp::Sem ( true, 1 )  ;
      
      for ( int i = 0; i++ < 10; ) {
	s1->Wait();
      }
    } else {

      compp::Sem *s1 = new compp::Sem (  )  ;
      std::cout << "*****************  Semaphore *****************\n";
      for ( int i = 0; i++ < 10; ) {

	s1->Post();
      }

      for ( int l = 0; l++ < 10; ) {

	s1->Wait();
      }
            std::cout << "***************** OK *****************\n";
    }
  }
  return 0;
}
